import { createRouter, createWebHistory, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { useMainStore } from '@/store/index';
let mainStore: any = null;

const routes: RouteRecordRaw[] = [
	{
		path: '',
		redirect: 'index'
	},
	{
		path: '/index',
		name: 'index',
		component: () => import('@/views/index/index.vue')
	},
	{
		path: '/index/verifiedMember',
		name: 'verifiedMember',
		component: () => import('@/views/index/verifiedMember/verifiedMember.vue')
	},
	{
		path: '/index/storeList',
		name: 'storeList',
		component: () => import('@/views/index/storeList/storeList.vue')
	},
	{
		path: '/matchmaker',
		name: 'matchmaker',
		component: () => import('@/views/matchmaker/matchmaker.vue')
	},
	{
		path: '/category',
		name: 'category',
		component: () => import('@/views/category/category.vue')
	},
	{
		path: '/matchmaker/becomeMatchmaker',
		name: 'becomeMatchmaker',
		component: () => import('@/views/matchmaker/becomeMatchmaker/becomeMatchmaker.vue')
	},
	{
		path: '/stores',
		name: 'stores',
		component: () => import('@/views/stores/stores.vue')
	},
	{
		path: '/stores/joinStores',
		name: 'joinStores',
		component: () => import('@/views/stores/joinStores/joinStores.vue')
	},
	{
		path: '/agreement/agreement',
		name: 'agreement',
		component: () => import('@/views/agreement/agreement.vue')
	},
	{
		path: '/my',
		name: 'my',
		component: () => import('@/views/my/my.vue')
	},
	{
		path: '/my/evaluationTrain',
		name: 'evaluationTrain',
		component: () => import('@/views/my/evaluationTrain/evaluationTrain.vue')
	},
	{
		path: '/my/evaluationTrain/score',
		name: 'score',
		component: () => import('@/views/my/evaluationTrain/score.vue')
	},
	{
		path: '/my/payRecord',
		name: 'payRecord',
		component: () => import('@/views/my/payRecord/payRecord.vue')
	},
	{
		path: '/my/viewRecord',
		name: 'viewRecord',
		component: () => import('@/views/my/viewRecord/viewRecord.vue')
	},
	{
		path: '/my/collection',
		name: 'collection',
		component: () => import('@/views/my/collection/collection.vue')
	},
	{
		path: '/my/categoryCollection',
		name: 'categoryCollection',
		component: () => import('@/views/my/categoryCollection/categoryCollection.vue')
	},
	{
		path: '/my/fans',
		name: 'fans',
		component: () => import('@/views/my/fans/fans.vue')
	},
	{
		path: '/my/team',
		name: 'team',
		component: () => import('@/views/my/team/team.vue')
	},
	{
		path: '/my/incomeDetails',
		name: 'incomeDetails',
		component: () => import('@/views/my/incomeDetails/incomeDetails.vue')
	},
	{
		path: '/my/storeIncomeDetails',
		name: 'storeIncomeDetails',
		component: () => import('@/views/my/storeIncomeDetails/storeIncomeDetails.vue')
	},
	{
		path: '/my/withdrawal',
		name: 'withdrawal',
		component: () => import('@/views/my/withdrawal/withdrawal.vue')
	},
	{
		path: '/my/accountManage',
		name: 'accountManage',
		component: () => import('@/views/my/accountManage/accountManage.vue')
	},
	{
		path: '/my/accountManage/addAccount',
		name: 'addAccount',
		component: () => import('@/views/my/accountManage/addAccount.vue')
	},
	{
		path: '/my/withdrawalRecord',
		name: 'withdrawalRecord',
		component: () => import('@/views/my/withdrawalRecord/withdrawalRecord.vue')
	},
	{
		path: '/my/storeLogin',
		name: 'storeLogin',
		component: () => import('@/views/my/storeLogin/storeLogin.vue')
	},
	{
		path: '/my/aboutUs',
		name: 'aboutUs',
		component: () => import('@/views/my/aboutUs/aboutUs.vue')
	},
	{
		path: '/my/guide',
		name: 'guide',
		component: () => import('@/views/my/guide/guide.vue')
	},
	{
		path: '/my/question',
		name: 'question',
		component: () => import('@/views/my/question/question.vue')
	},
	{
		path: '/my/messageRecords',
		name: 'messageRecords',
		component: () => import('@/views/my/messageRecords/messageRecords.vue')
	},
	{
		path: '/my/order',
		name: 'order',
		component: () => import('@/views/my/order/order.vue')
	},
	{
		path: '/my/poster',
		name: 'poster',
		component: () => import('@/views/my/poster/poster.vue')
	},
	{
		path: '/memberDetail',
		name: 'memberDetail',
		component: () => import('@/views/userDetail/memberDetail.vue')
	},
	{
		path: '/userDetail',
		name: 'userDetail',
		component: () => import('@/views/userDetail/userDetail.vue')
	},
	{
		path: '/matchmakerDetail',
		name: 'matchmakerDetail',
		component: () => import('@/views/userDetail/matchmakerDetail.vue')
	},
	{
		path: '/registered',
		name: 'registered',
		component: () => import('@/views/registered/registered.vue')
	},
	{
		path: '/registered/avatar',
		name: 'avatar',
		component: () => import('@/views/registered/avatar/avatar.vue')
	}
];

const router = createRouter({
	history: createWebHashHistory(),
	routes
});

router.beforeEach((to, from, next) => {
	if (mainStore == null) {
		mainStore = useMainStore();
	}
	console.log('from.path：',from.path)
	if ((from.path === '/userDetail' || from.path === '/memberDetail' || from.path === '/verifiedMember' || from.path === '/becomeMatchmaker') && (to.path === '/matchmaker' || to.path === '/index' || to.path === '/stores')) {
		mainStore.isUserDetailPath = true;
	} else {
		mainStore.isUserDetailPath = false;
	}
	next();
});

export default router;
